package org.boyan.utils;

import org.boyan.common.util.DateUtils;

import java.util.Date;

/*
* 自动生成ID的工具类，自动生成一个ID，用日期+001的流水号来生成
* */
public class IdGenerate {

    private static int initNumber=0;

    public static String getId(){
        String dateStr= DateUtils.formatDate(new Date(),"yyyyMMdd");
        initNumber=initNumber+1;
        String numberStr=getNumberStr(initNumber);
        return dateStr+"-"+numberStr;
    }

    private static String getNumberStr(int number){
        String str=String.valueOf(number);
        int dif=4-str.length();
        StringBuffer stringBuffer=new StringBuffer();
        for(int i=0;i<dif;i++){
            stringBuffer.append("0");
        }
        return stringBuffer.toString()+str;
    }

}
